export class Base64Ex {

    static GetBase64(uint8Array: Uint8Array, width: number, height: number): string {
        var canv: Laya.HTMLCanvas = new Laya.HTMLCanvas(true);
        canv.lock = true;
        canv.size(width, height);
        var ctx2d = canv.getContext('2d');
        //@ts-ignore
        var imgdata: ImageData = ctx2d.createImageData(width, height);
        //@ts-ignore
        imgdata.data.set(uint8Array);
        //@ts-ignore
        ctx2d.putImageData(imgdata, 0, 0);;
        let bs = canv.source.toDataURL();
        canv.destroy();
        return bs;
    }

    static GetUInt8Array(base64Data: string): Uint8Array {
        var byteString;
        if (base64Data.split(",")[0].indexOf("base64") >= 0) {
            byteString = atob(base64Data.split(",")[1]);
        } else {
            byteString = Laya.Browser.window.unescape(base64Data.split(",")[1]);
        }
        var mimeString = base64Data.split(",")[0].split(":")[1].split(";")[0];
        var ia = new Uint8Array(byteString.length);
        for (var i = 0; i < byteString.length; i++) {
            ia[i] = byteString.charCodeAt(i);
        }
        return ia;
    }

}